home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 7.0 KB | 251 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: RulerFacet.cpp
- // Release Version: $ 1.0d1 $
- //
- // Author: Anthone Burbidge
- // Creation Date: 3/28/94
- //
- // Copyright: © 1993, 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- // ----- Macintish Includes -----
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef _SHAPE_
- #include "Shape.h"
- #endif
-
- // ----- Framework Includes -----
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- // ----- TextPart Includes -----
-
- #ifndef _RulerObject_
- #include "RulerObject.h"
- #endif
-
- #ifndef _RULERFACET_
- #include "RulerFacet.h"
- #endif
-
- #ifndef _RULERFRAME_
- #include "RulerFrame.h"
- #endif
-
- #ifndef _TEXTUTIL_
- #include "TextUtil.h"
- #endif
-
- #ifndef _TEXTPART_
- #include "TextPart.h"
- #endif
-
- #pragma segment TextPartSegment
-
- //========================================================================================
- // CLASS CRulerFacet
- //========================================================================================
-
- const RGBColor CRulerFacet::kGray = { 0xB000, 0xB000, 0xB000 };
- const RGBColor CRulerFacet::kBlack = { 0x0000, 0x0000, 0x0000 };
-
- //----------------------------------------------------------------------------------------
- // CRulerFacet::CRulerFacet
- //----------------------------------------------------------------------------------------
-
- CRulerFacet::CRulerFacet() :
- FW_CFacet(),
- fTextPart(NULL),
- fSelectedTool(0)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CRulerFacet::IRulerFacet
- //----------------------------------------------------------------------------------------
-
- void CRulerFacet::IRulerFacet(XMPFacet* facet, CTextPart* textPart)
- {
- InitFacet(facet);
- fTextPart = textPart;
-
- // ----- Calculate the tool positions
- FW_SPlatformRect toolArea;
- short center = CTextPart::kRulerWidth / 2;
-
- toolArea.top = CTextPart::kRulerRulerHeight + 4;
- toolArea.left = center - (CTextPart::kToolWidths + 4) * 2;
- toolArea.bottom = toolArea.top + CTextPart::kToolHeights;
- toolArea.right = toolArea.left + CTextPart::kToolWidths;
-
- // ----- Set the tool area rectangles
- for (short i = 0; i < CTextPart::kNumberOfTools; i++)
- {
- fToolAreas[i] = toolArea;
- toolArea.left += CTextPart::kToolWidths + 4;
- toolArea.right += CTextPart::kToolWidths + 4;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CRulerFacet::~CRulerFacet
- //----------------------------------------------------------------------------------------
-
- CRulerFacet::~CRulerFacet()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CRulerFacet::Draw
- //----------------------------------------------------------------------------------------
-
- void CRulerFacet::Draw(FW_CGraphicContext *gc)
- {
- XMPShape* clipShape = ::NewXMPShape();
- gc->GetClipShape(clipShape);
-
- ::EraseRgn(clipShape->GetQDRegion());
-
- CRulerFrame* frame = (CRulerFrame *) GetFrame();
-
- FW_CRect frameBounds;
- frame->GetFrameShapeBounds(&frameBounds);
-
- FW_SPlatformRect qdFrameBounds = frameBounds;
-
- DrawBackground(clipShape->GetQDRegion(), qdFrameBounds);
- DrawTools(clipShape->GetQDRegion(), qdFrameBounds);
- DrawRuler(clipShape->GetQDRegion(), qdFrameBounds);
-
- delete clipShape;
- }
-
- //----------------------------------------------------------------------------------------
- // CRulerFacet::DoMouseDown
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CRulerFacet::DoMouseDown(const FW_CPoint& where, XMPEventData event)
- {
- FW_UNUSED(event);
-
- FW_CGraphicContext di(this->GetXMPFacet());
-
- const CTextPart::Justification justifyTable[] = { kLeftJust, kCenterJust,
- kRightJust, kFullJust };
-
- for (short i = 0; i < CTextPart::kNumberOfTools; i++)
- {
- FW_CRect rect(fToolAreas[i]);
- if (rect.Contains(where))
- {
- {
- CTextDrawInitiator di((CTextFacet *) fTextPart->GetActiveFrame()->GetActiveFacet());
- fTextPart->SetSelectionJustification(justifyTable[i]);
- }
-
- if (i != fSelectedTool)
- {
- FW_SPlatformRect invertRect = fToolAreas[fSelectedTool];
- ::InsetRect(&invertRect, 1, 1);
- ::InvertRect(&invertRect);
-
- invertRect = fToolAreas[i];
- ::InsetRect(&invertRect, 1, 1);
- ::InvertRect(&invertRect);
- }
- fSelectedTool = i;
- break;
- }
- }
- return true;
- }
-
- //----------------------------------------------------------------------------------------
- // CRulerFacet::MouseEnter
- //----------------------------------------------------------------------------------------
-
- void CRulerFacet::MouseEnter(const FW_CPoint& where)
- {
- FW_UNUSED(where);
- SetCursor(&XMPASLMQDGlobals.arrow);
- }
-
- //----------------------------------------------------------------------------------------
- // CRulerFacet::DrawBackground
- //----------------------------------------------------------------------------------------
-
- void CRulerFacet::DrawBackground(FW_PlatformRegion invalidRgn, const FW_SPlatformRect& boundingBox)
- {
- FW_UNUSED(invalidRgn);
-
- FW_SPlatformRect grayArea = boundingBox;
- grayArea.top += CTextPart::kRulerRulerHeight;
-
- ::RGBForeColor(&kGray);
- ::FillRect(&grayArea, &XMPASLMQDGlobals.black);
- ::RGBForeColor(&kBlack);
- ::PenNormal();
-
- ::MoveTo(boundingBox.left, boundingBox.bottom - 1);
- ::LineTo(boundingBox.right, boundingBox.bottom - 1);
- }
-
- //----------------------------------------------------------------------------------------
- // CRulerFacet::DrawTools
- //----------------------------------------------------------------------------------------
-
- void CRulerFacet::DrawTools(FW_PlatformRegion invalidRgn, const FW_SPlatformRect& boundingBox)
- {
- FW_UNUSED(invalidRgn);
- FW_UNUSED(boundingBox);
-
- FW_CAcquireASLMResourceAccess aq;
-
- const CTextPart::Justification justifyTable[] = { kLeftJust, kCenterJust, kRightJust, kFullJust };
- const CTextPart::Justification justify = fTextPart->GetSelectionJustification();
-
- // ----- Draw the tools
- for (short resourceId = 2021; resourceId <= 2024; resourceId++)
- {
- PicHandle pictHandle = ::GetPicture(resourceId);
- ::DrawPicture(pictHandle, &fToolAreas[resourceId - 2021]);
- if (justifyTable[resourceId - 2021] == justify)
- {
- FW_SPlatformRect invertRect = fToolAreas[resourceId - 2021];
- ::InsetRect(&invertRect, 1, 1);
- ::InvertRect(&invertRect);
- fSelectedTool = resourceId - 2021;
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CRulerFacet::DrawRuler
- //----------------------------------------------------------------------------------------
-
- void CRulerFacet::DrawRuler(FW_PlatformRegion invalidRgn, const FW_SPlatformRect& boundingBox)
- {
- FW_UNUSED(invalidRgn);
- FW_UNUSED(boundingBox);
-
- FW_CAcquireASLMResourceAccess aq;
-
- FW_SPlatformRect rulerArea = { 0, 0, CTextPart::kRulerHeight, CTextPart::kRulerWidth };
- PicHandle rulerHandle = ::GetPicture(2001);
- ::DrawPicture(rulerHandle, &rulerArea);
- }
-